
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulator.engine;

/**
 *
 * @author 500384
 */
public class WaterHeater 
{
    
    // population in simulated building/area
    private int population;
    
    // average consumption pr person
    private int consumption;
    
    // the temperature the water shall heat to
    private int insideT;
    
    // temperature of water when it enters building
    private int outsideT;
    
    // mass of water in kilograms, which is the same as litre
    private int mass;
    
    // specific heat capacity denoted in joule per kilogram per celcius
    private  double specificHeat;
    
    public int getPopulation() {
        return population;
    }

    public void setPopulation(int aPopulation) {
        population = aPopulation;
    }
    public int getConsumption() {
        return consumption;
    }

    public void setConsumption(int aConsumption) {
        consumption = aConsumption;
    }

    public int getInsideT() {
        return insideT;
    }

    public void setInsideT(int aInsideT) {
        insideT = aInsideT;
    }

    public int getOutsideT() {
        return outsideT;
    }

    public void setOutsideT(int aOutsideT) {
        outsideT = aOutsideT;
    }
    
    //default constructor
    public WaterHeater () { }
    
    //constructor for a waterheater object consisting of total consumption(not depending on the population of the building),
    //expected temperature of the water when it enters the building and the temperature it will heat to 
    public WaterHeater (int consumption, int insideT, int outsideT) {
        this.consumption = consumption;
        this.insideT =  insideT;
        this.outsideT = outsideT;
        population = 1;
    }
    
    /**
     * Konstruktør skrevet av Kim Rune
     * @param population
     * @param consumption
     * @param insideT
     * @param outsideT 
     */
    public WaterHeater(int consumption, double insideT, double outsideT)
    {
        this.consumption = consumption;
        this.insideT = (int) insideT;
        this.outsideT = (int) outsideT;
    }
    
    //constructor for a waterheater object consisting of total consumption depending on the population of the building
    //and the average consumptions of each inhabitants, expected temperature of the water when it enters the building 
    //and the temperature it will heat to inside the building
    public WaterHeater (int population, int consumption, int insideT, int outsideT) { 
        this.population = population;
        this.consumption = consumption;
        this.insideT =  insideT;
        this.outsideT = outsideT;
    }
    
    
    
    //calculates the power consumption based on the total mass of the water consumed, the specific heat of the water when it enters the building
    //and the difference in temperature between outside the building and the inside of the waterheater
    public double PowerConsumption (double outsideT) {
        //depending on the temperature of the water when it enters the building the specific heat of the water changes
        switch((int)outsideT) {
            case 0: specificHeat = 4.217;
                break;
            case 1: specificHeat = 4.213;
                break;
            case 2: specificHeat = 4.210;
                break;
            case 3: specificHeat = 4.207;
                break;
            case 4: specificHeat = 4.205;
                break;
            case 5: specificHeat = 4.202;
                break;
            case 6: specificHeat = 4.200;
                break;
            case 7: specificHeat = 4.198;
                break;
        }
        
        
        mass = population * consumption;
        int deltaT = (insideT - (int)outsideT);
        
        // amount of heat required to raise the temperature of the water
        double heatEnergyJoule = mass * specificHeat * deltaT;
        double jouleToKWH = heatEnergyJoule / (3600);
        
        return jouleToKWH;
    }
}
